 <template>
   <view style="width: 100%;height: 100%;">
     <view class="root">
       <view class="content">
         <uni-forms ref="formRef" :model="form" validateTrigger="blur" label-position="top" label-width="100%"
           err-show-type="toast">
           <view class="content-wrapper">
             <view class="content-inner-wrapper">
               <uni-forms-item label="JS障碍人员：" name="name" required key="name">
                 <view class="form-content-item" :class="form.name ?  '' : 'input-item'">
                   <uni-easyinput type="text" :maxlength="30" v-model.trim="form.name" :inputBorder="false"
                     placeholder="请填写" :clearable="true" disabled />
                 </view>
               </uni-forms-item>
               <uni-forms-item label="发病时间：" name="morbidityTime" required key="morbidityTime">
                 <view class="form-content-item" :class="form.morbidityTime ?  '' : 'input-item'">
                   <uni-datetime-picker v-model="form.morbidityTime" type="datetime" :hide-second="true"
                     :end="getEndOfTodayTimestamp()">
                     <uni-easyinput type="text" v-model="form.morbidityTime" :inputBorder="false" placeholder="请选择"
                       :clearable="true" disabled />
                   </uni-datetime-picker>
                   <image :src="baseImgUrl + 'day-icon2.png'" style="width: 30rpx;height: 30rpx;padding:0 10rpx;">
                 </view>
               </uni-forms-item>
               <uni-forms-item label="发病地点：" name="morbidityAddress" required style="margin-bottom: 0;">
                 <uni-easyinput type="text" v-model="form.morbidityAddress" :inputBorder="false" placeholder="请选择"
                   :clearable="false">
                   <image style="width: 30rpx;height: 40rpx;margin-right: 10rpx;" @click="handleMap"
                     :src="`${baseImgUrl}map-icon.png`" slot="right"></image>
                 </uni-easyinput>
               </uni-forms-item>
             </view>
           </view>
         </uni-forms>
       </view>
       <view class="bottom">
         <yy-button-submit @submit="onSubmit"></yy-button-submit>
       </view>
     </view>
     <yy-watermark></yy-watermark>
   </view>
 </template>

 <script>
   import moment from '../utils/moment'
   import {
     addWbMorbidityRecords,
     phoneAcquisitionRecordsSave,
     registeredPhoneSave
   } from '@/api/api'
   import uploadFileMixin from '@/utils/upload-file-mixin'
   import {
     Toast,
     getOptionsParams,
     idCardRule,
     isLoading,
     navBack,
     phoneRule,
     getEndOfTodayTimestamp,
     navTo
   } from '@/utils/util'
   export default {
     mixins: [uploadFileMixin],
     data() {
       return {
         baseImgUrl: this.$baseImgUrl,
         clientId: this.$clientId,
         clientSecret: this.$clientSecret,
         visibleCamera: false,
         form: this.initForm(),
         routerParams: {},
         showTips: false,
         rules: {
           name: {
             rules: [{
               required: true,
               errorMessage: "请填写JS障碍人员！",
             }]
           },
           morbidityTime: {
             rules: [{
               required: true,
               errorMessage: "请填写发病时间！",
             }]
           },
           morbidityAddress: {
             rules: [{
               required: true,
               errorMessage: "请填写发病地点！",
             }]
           },
         }
       }
     },
     onLoad(options) {
       this.routerParams = getOptionsParams(options)
       this.form.name = this.routerParams.name
     },
     onReady() {
       this.$refs.formRef.setRules(this.rules)
     },
     methods: {
       getEndOfTodayTimestamp,
       initForm() {
         return {
           name: '',
           morbidityTime: '',
           morbidityAddress: '',
           log: '',
           lat: '',
         }
       },
       onSubmit() {
         this.$refs.formRef.validate().then(() => {
             let data = {
               mentalPatientId: this.routerParams.id,
               ...this.form,
               morbidityTime: moment(this.form.morbidityTime).format('YYYY/MM/DD HH:mm')
             };

             isLoading(true)
             addWbMorbidityRecords(data).then((res) => {
                 if (res.code == 200) {
                   setTimeout(() => {
                     navBack();
                   }, 100)
                   uni.$emit('ill-health-add')
                 }
                 Toast(res.message);
               })
               .finally(() => {
                 isLoading(false)
               })
           })
           .catch(() => {})
       },
       handleCamera() {
         this.visibleCamera = true;
       },
       onParsedSuccess(value) {
         const {
           domicileAddress,
           userName,
           idcard,
           nation
         } = value;
         this.$set(this.form, "sellPersonName", userName);
         this.$set(this.form, "sellPersonIdcard", idcard);
         this.visibleCamera = false;
       },
       handleGetImei() {
         navTo({
           url: '/itemRegistration/getImei'
         })
       },
       handleMap() {
         uni.chooseLocation({
           success: (res) => {
             let {
               longitude,
               latitude,
               address
             } = res;
             this.form.morbidityAddress = address
             this.form.log = longitude
             this.form.lat = latitude
           },
           fail: function(err) {
             console.log(err, "错误的");
           },
         });
       }
     }
   }
 </script>

 <style lang="scss" scoped>
   @import '@/styles/uni-form-label-top.scss';

   .root {
     display: flex;
     width: 100%;
     height: 100%;
     flex-direction: column;
     background: #F9F9F9;

     .content {
       flex: 1;
       height: 0;
       overflow: auto;

       .content-wrapper {
         background: #FFFFFF;
         box-shadow: 0rpx 3rpx 6rpx 1rpx rgba(207, 207, 207, 0.1608);
         border-radius: 8rpx 8rpx 8rpx 8rpx;
         padding: 40rpx 20rpx;
         margin-bottom: 10rpx;

         .label-IMEI {
           display: flex;
           justify-content: space-between;
           align-items: center;
           height: 72rpx;

           /deep/.is-required {
             color: #dd524d;
             font-weight: bold;
           }

           .l-text {
             font-weight: 500;
             font-size: 30rpx;
             color: #666666;
           }

           .r-text {
             font-weight: 400;
             font-size: 22rpx;
             color: #D91313;
             display: flex;
             justify-content: space-between;
             align-items: center;

             /deep/.u-icon {
               margin-left: 5rpx;
             }
           }
         }
       }

       .pawn-list-wrapper {
         background: #F9F9F9;
         padding: 25rpx;
         margin-bottom: 10rpx;

         .title-name {
           display: flex;
           justify-content: space-between;
           margin-bottom: 23rpx;

           .name-i {
             font-weight: bold;
             font-size: 32rpx;
             color: #181818;
           }

           .delete-i {
             display: flex;
             align-items: center;
             font-weight: 500;
             font-size: 26rpx;
             color: #F94A4A;
             flex-shrink: 0;

             .text-delete {
               margin-left: 10rpx;
             }
           }
         }

         .i-item {
           margin-bottom: 15rpx;
           display: flex;

           .i-label {
             font-weight: 500;
             font-size: 28rpx;
             color: #999999;
             width: 119rpx;
             margin-right: 16rpx;
             position: relative;
             text-align: justify;
             text-align-last: justify;
             flex-shrink: 0;



             &::after {
               content: ':';
               position: absolute;
               right: -8rpx;
             }
           }

           .i-value {
             font-weight: bold;
             font-size: 28rpx;
             color: #101010;
           }

         }
       }

       .datetime-picker-wrapper {
         display: flex;
         align-items: center;
         justify-content: space-between;

         .text-t {
           font-weight: 500;
           font-size: 30rpx;
           color: #666666;
         }

         .t-item {
           font-weight: 400;
           font-size: 28rpx;
           color: #A2A2A2;
           width: 304rpx;
           height: 70rpx;
           background: #F9F9F9;
           border-radius: 8rpx 8rpx 8rpx 8rpx;
           border: 1rpx solid #F1EEEE;
           display: flex;
           align-items: center;
           justify-content: center;
         }

         .has-value {
           font-weight: bold;
           font-size: 30rpx;
           color: #181818;
         }
       }
     }
   }

   .IMEI-content-wrapper {
     padding: 63rpx 123rpx 56rpx 123rpx;
     width: 590rpx;

     .t-top {
       font-weight: bold;
       font-size: 36rpx;
       color: #181818;
       text-align: center;
     }

     .t-bottom {
       text-align: center;
       font-weight: 500;
       font-size: 28rpx;
       color: #333333;
       margin-top: 45rpx;
       margin-bottom: 93rpx;
     }

     .know-b {
       width: 320rpx;
       height: 88rpx;
       display: flex;
       align-items: center;
       justify-content: center;
       background: #2488F5;
       border-radius: 44rpx 44rpx 44rpx 44rpx;
       border: 1rpx solid #ACCBEC;
       margin: 0 auto;
       font-weight: 500;
       font-size: 36rpx;
       color: #F9F9F9;
     }
   }
 </style>